var express = require('express');
var db = require('./db.js')

var router = express.Router()
var bodyParser = require('body-parser');
var md5 = require('md5-nodejs');
var urlencodedParser = bodyParser.urlencoded({ extended: false })
router.post('/addServer',urlencodedParser,async function(req,res){
    var {uid,collection,history,progress}=req.body;
    var sql=`insert into sync (uid,collection,history,progress) values (${uid},'${collection}','${history}','${progress}')`;
    const data=await db.doSql(sql)
    res.send(JSON.stringify(db.hand(data)))
})
router.post('/updateServer',urlencodedParser,async function(req,res){
    var {uid,collection,history,progress}=req.body;
    var sql=`update sync set collection='${collection}',history='${history}',progress='${progress}' where uid=${uid}`;
    const data=await db.doSql(sql)
    res.send(JSON.stringify(db.hand(data)))
})
router.get('/getServer',async function(req,res){
    var {uid}=req.query;
    var sql=`select * from sync where uid=${uid}`;
    const data=await db.doSql(sql)
    res.send(JSON.stringify(db.hand(data)))
})
module.exports = router